package com.itheima;

import com.itheima.entity.Result;
import com.itheima.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class ExceptionsHandler {
    @ExceptionHandler(BusinessException.class)//可以直接写@ExceptionHandler,不指明异常类，会自动映射
    @ResponseBody
    public Result customGenericExceptionHandler(BusinessException exception) { //还可以声明接收其他任意参数
        return new Result(false, exception.getMsg());
    }
}
